<template>
  <div class="aui-card-list">
  <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}" @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item label="表名">
          <el-input v-model="dataForm.tableName" placeholder="表名" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="表说明">
          <el-input v-model="dataForm.comments" placeholder="表说明" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="生成模块名">
          <el-input v-model="dataForm.moduleName" placeholder="生成模块名" clearable></el-input>
        </el-form-item>
      </el-col>
      <template v-slot:other>
        <el-col :span="6">
        <el-form-item label="生成功能名">
          <el-input v-model="dataForm.functionName" placeholder="生成功能名" clearable></el-input>
        </el-form-item>
      </el-col>
      </template>
  </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar setting>
        <template v-slot:buttons>
          <el-button type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
      <vxe-table ref="xTable" auto-resize :height="this.tableHeight" :loading="dataListLoading"
        class="vxe-table-element" @select-change="dataListSelectionChangeHandleVex"
        @select-all="dataListSelectionAllChangeHandleVex" :data="dataList" max-height="auto">
        <vxe-table-column type="index" width="50" align="center"></vxe-table-column>
        <vxe-table-column field="sourceName" title="数据源名称">
        </vxe-table-column>
        <vxe-table-column field="tableName" title="表名">
        </vxe-table-column>
        <vxe-table-column field="functionName" title="功能名">
        </vxe-table-column>
        <vxe-table-column field="tplCategory" title="生成模板分类" width="100">
        </vxe-table-column>
        <vxe-table-column field="moduleName" title="生成模块名" width="100">
        </vxe-table-column>
        <vxe-table-column field="functionAuthor" title="生成功能作者" width="120">
        </vxe-table-column>
        <vxe-table-column field="updater" title="更新者" width="100">
        </vxe-table-column>
        <vxe-table-column field="updateDate" title="更新时间" width="140" align="center">
        </vxe-table-column>
        <vxe-table-column title="handle" fixed="right" width="220">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row)">
              {{ $t('update') }}
            </el-button>
            <el-button type="text" size="small" @click="codeGene(scope.row)">生成代码</el-button>
            <el-button type="text" size="small" @click="menuGene(scope.row)">生成菜单</el-button>
            <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">
              {{ $t('delete') }}
            </el-button>
          </template>
        </vxe-table-column>
      </vxe-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './addMenu'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      addOrUpdateVisible: false,
      mixinViewModuleOptions: {
        getDataListURL: '/gen/genTable/page',
        getDataListIsPage: true,
        deleteURL: '/gen/genTable',
        deleteIsBatch: false,
        exportURL: '/gen/genTable/export'
      },
      headLock: true,
      dataForm: {
        tableName: '',
        comments: '',
        functionAuthor: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let title = '新增'
      let id, params
      if (row) {
        title = row.comments
        id = row.id
      }
      // 打开路由
      var router = {
        name: 'gen-genTable-editTab',
        id: id,
        menuId: this.$route.meta.menuId,
        oldName: 'gen-genTable',
        path: 'gen/genTable-editTab',
        title: '代码生成工具--' + title
      }
      if (row) {
        params = {
          dsCode: row.sourceCode,
          tableName: row.tableName,
          childTableCode: row.childTableCode,
          activeName: 'basic'
        }
      } else {
        params = {
          activeName: 'basic'
        }
      }
      this.$options.methods.openNewTab(this.$router, router, params)
    },
    codeGene (row) {
      let title, id
      if (row) {
        title = row.comments
        id = row.id
      }
      // 打开路由
      var router = {
        name: 'gen-genTable-editTab',
        id: id,
        menuId: this.$route.meta.menuId,
        oldName: 'gen-genTable',
        path: 'gen/genTable-editTab',
        title: '代码生成工具--' + title
      }
      var params = {
        dsCode: row.sourceCode,
        tableName: row.tableName,
        childTableCode: row.childTableCode,
        activeName: 'gene'
      }
      this.$options.methods.openNewTab(this.$router, router, params)
    },
    menuGene (row) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.tableId = row.id
        this.$refs.addOrUpdate.dataForm.sourceCode = row.sourceCode
        this.$refs.addOrUpdate.dataForm.name = row.functionName
        this.$refs.addOrUpdate.dataForm.tableName = row.tableName
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>
